package com.xiaomaoguai.redis.sub2;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * @ FileName: PubSubTest3Main.java
 * @ Author: WeiHui-Z
 * @ Date: 2017/6/5 19:40
 * @ Version: v1.0.0
 */
@ContextConfiguration(locations = {"classpath:spring-pubSub-3.xml"})
public class PubSubTest3Main extends AbstractJUnit4SpringContextTests {

    private static final Logger LOGGER = LoggerFactory.getLogger(PubSubTest3Main.class);

    @Resource
    private RedisTemplate redisTemplate;

    @Test
    public void testPublishString() throws Exception {
        Map<String, String> message = new HashMap<>();

        message.put("userId", "B00120210");
        message.put("extendField", "562548");

        do {
            String channel = PushMsgEnum.getRandomPushType();
            LOGGER.info("当前频道:{}", channel);
            redisTemplate.convertAndSend(channel, message);
            TimeUnit.SECONDS.sleep(3);
        } while (true);
    }

}
